package com.zxg.androidbuslearn

import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.preference.PreferenceManager
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.Toast

/**
 * 作者: 赵小刚
 * 生成时间: 2018/11/5.
 * 版本: 1.0
 * 简介:
 * 修改记录:
 */
class LoginActivity : BaseActivity() {

    private var pref : SharedPreferences? = null
    private var editor : SharedPreferences.Editor? = null

    private var edit_user: EditText? = null
    private var edit_pwd: EditText? = null
    private var btn_login: Button? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.login)
        pref = PreferenceManager.getDefaultSharedPreferences(this)
        initView()
    }

    fun initView() {
        edit_user = findViewById(R.id.edit_user)
        edit_pwd = findViewById(R.id.edit_pawd)
        btn_login = findViewById(R.id.btn_login)
        btn_login!!.setOnClickListener{
            val user = edit_user!!.text.toString()
            val pwd = edit_pwd!!.text.toString()
            if (user.equals("123") && pwd == "123") {
                editor = pref!!.edit()
                editor!!.putString("User", user)
                editor!!.putString("Pawd", pwd)
                editor!!.commit()
                val intent = Intent(this, LocalReceuverActivity::class.java)
                startActivity(intent)
                Toast.makeText(this, "对了", Toast.LENGTH_LONG).show()
                finish()
            } else {
                Toast.makeText(this, "错了", Toast.LENGTH_LONG).show()
            }
        }
    }
}